<template>
  <div>
    <div id="div3">
      <el-table
          :data="tableData1"
          border
          style="width: 81.7%">

        <el-table-column
            label="申请用户"
            prop="name"
            width="275">
        </el-table-column>
        <el-table-column
            prop="telephone"
            label="电话"
            width="250">
        </el-table-column>
        <el-table-column
            prop="status"
            label="状态"
            width="250">
          <template  #default="scope">
            {{scope.row.status == '1' ? "审核未通过" : scope.row.status == '2' ? "待审核":
              scope.row.status == '3' ? "审核通过" :''}}
          </template>
        </el-table-column>
        <el-table-column
            label="操作"
            width="250">
          <template #default="scope">
            <el-button  type="primary" v-if="scope.row.status == '2'" @click="showrubyid(scope.row)">查看</el-button>
            <el-button  type="primary"  v-if="scope.row.status == '3'" disabled>已通过</el-button>
            <el-button  type="primary"  v-if="scope.row.status == '1'" disabled>已拒绝</el-button>
            <el-button v-if="scope.row.status == '1'" @click="detelerent(scope.row)">删除</el-button>
            <el-button v-if="scope.row.status == '3'" @click="detelerent(scope.row)">删除</el-button>
            <el-button v-if="scope.row.status == '2'" disabled>删除</el-button>
          </template>
        </el-table-column>
      </el-table>


      <el-dialog v-model="orderInfo1" title="用户申请" :before-close="close1" class="dialog1">
        <p >姓名:{{tableData2.name}}</p>
        <p >地址:{{tableData2.place}}</p>
        <p >电话:{{tableData2.telephone}}</p>
        <el-button @click="refuse()">拒绝</el-button>
        <el-button @click="registered(),accept()">通过</el-button>
        <el-button @click="close1()">关闭</el-button>
      </el-dialog>
    </div>
  </div>
  </template>



  <script>
    import request from "@/utils/request";
    import router from "@/router";


    export default {
    name: "OrderHistory",
    data(){
    return{
      id:'',
    changeInfo: false,
    AfterSale:[
    ],
    orderInfo1:false,
    orderInfo2:false,
      tableData1: [],
      tableData2:{
        name:'',
        place:'',
        telephone:'',
        account:'',
        password:'',
      },
      registeredForm: {
        name: '',
        account: '',
        tele: '',
        defaultTradePlace: '',
        password: ''
      },
  }
  },
    methods:{
      showrentuser(){
        request.get("http://localhost:8081/seller/showrentuser").then(res => {
          if (res.flag) {
            this.tableData1 = res.data;
            console.log("1",this.tableData1)
            this.$message({
              type: 'success',
              message: res.msg
            })
          } else {
            this.$message.error(res.msg);
          }
        })
      },
      showrubyid(row){
        this.orderInfo1=true;
        this.id=row.id
        request.get("http://localhost:8081/seller/showrubyid?id="+this.id).then(res =>{
          if (res.flag) {
            this.tableData2 = res.data;
            console.log('show',this.tableData2)
            this.registeredForm.name=this.tableData2.name
            this.registeredForm.tele=this.tableData2.telephone
            this.registeredForm.defaultTradePlace=this.tableData2.place
            this.registeredForm.account=this.tableData2.account
            this.registeredForm.password=this.tableData2.password
            this.$message({
              type: 'success',
              message: res.msg
            })
          }
          else {
            this.$message.error(res.msg);
          }
        })
      },
      // registered() {
      //     request.post("http://localhost:8082/user/register?name="+this.tableData2.name+"&default_trade_place="+this.tableData2.place
      //     +"&tele="+this.tableData2.telephone+"&account="+this.tableData2.account+"&password="+this.tableData2.password).then(res => {
      //       if (res.flag) {
      //         this.$message({
      //           type: 'success',
      //           message: res.msg
      //         })
      //       } else {
      //         this.$message.error(res.msg)
      //         this.account = ''
      //         this.password = ''
      //       }
      //     })
      // },
      registered() {
        request.post("http://localhost:8082/user/register",this.registeredForm).then(res => {
          if (res.flag) {
            this.$message({
              type: 'success',
              message: res.msg
            })
          } else {
            this.$message.error(res.msg)
            this.account = ''
            this.password = ''
          }
        })
      },
      detelerent(row){
        this.id=row.id
        request.get("http://localhost:8081/seller/detelerent?id="+this.id).then(res =>{
          if (res.flag) {
            // this.tableData2 = res.data;
            this.$message({
              type: 'success',
              message: res.msg
            })
          }
          else {
            this.$message.error(res.msg);
          }
        })
      },
      accept(){
        request.get("http://localhost:8081/seller/acceptrent?id="+this.id).then(res =>{
          if (res.flag) {
            // this.tableData2 = res.data;
            this.$message({
              type: 'success',
              message: res.msg
            })
          }
          else {
            this.$message.error(res.msg);
          }
        })
      },
      refuse(){
        request.get("http://localhost:8081/seller/refuserent?id="+this.id).then(res =>{
          if (res.flag) {
            // this.tableData2 = res.data;
            this.$message({
              type: 'success',
              message: res.msg
            })
          }
          else {
            this.$message.error(res.msg);
          }
        })
      },

    open() {
    this.changeInfo = true;
  },
    change(){
    this.changeInfo = false;
  },
    open1(row) {
    this.orderInfo1=true;
  },
    close1() {
    this.orderInfo1 = false;
  },
  },
    created() {
    this.showrentuser()
  },
  }
  </script>
  
  <style scoped>

  </style>
  